/**
 * 组装报错单
 */
app.controller('btnCtrl', ['$scope', '$http', BtnController]);
function BtnController($scope, $http){
    console.log('------$scope.menuId1-----', $scope.menuId);
    console.log('------$scope.buttonArr1-----', $scope.buttonArr);

    $scope.bindBtn = function(event) {
        var datas = $scope.getSelectedRows();
        switch(event){
            case 'event-to-export': {//导出
                $scope.doExport('/api/inter/tccAssembleError/export');
                break;
            }

            case 'event-to-errorHandle': {//报错处理
                if(datas.length == 0) {
                    layer.alert('尚未选中数据');
                } else {
                    var choooseDatas = JSON.stringify(datas);
                    //处理状态（0未处理、1不处理、2补发货、3已发货）
                    layer.alert('请选择报错处理的方式', {
                        btn: ['不处理', '补发货'],
                        btnAlign: 'c', // 按钮居中显示
                        btn1: function(){//不处理
                            layer.confirm('确定要将所选的报错单处理成\"不处理\"吗？', { icon: 3 }, function() {
                                layer.msg('处理中', { icon: 16, shade: 0.01 });
                                $http.post('/api/inter/tccAssembleError/errorHandle', {}, {params: {choooseDatas: choooseDatas,handleStatus:1}})
                                    .success(function (res) {
                                        if (res.code == 0) {
                                            layer.msg(res.msg);
                                            setTimeout(function(){
                                                layer.closeAll();
                                                location.reload();
                                            }, 3000);
                                        } else {
                                            layer.msg(res.msg);
                                            layer.closeAll();
                                        }
                                    })
                                    .error(function(result){
                                        layer.close();
                                        layer.msg("操作失败，请稍后再试！", {icon: 2});
                                    });
                            }, function() {});
                        },
                        btn2: function(){//补发货
                            layer.confirm('确定要将所选的报错单处理成\"补发货\"吗？', { icon: 3 }, function() {
                                layer.msg('处理中', { icon: 16, shade: 0.01 });
                                $http.post('/api/inter/tccAssembleError/errorHandle', {}, {params: {choooseDatas: choooseDatas,handleStatus:2}})
                                    .success(function (res) {
                                        if (res.code == 0) {
                                            layer.msg(res.msg);
                                            setTimeout(function(){
                                                layer.closeAll();
                                                location.reload();
                                            }, 3000);
                                        } else {
                                            layer.msg(res.msg);
                                            layer.closeAll();
                                        }
                                    })
                                    .error(function(result){
                                        layer.close();
                                        layer.msg("操作失败，请稍后再试！", {icon: 2});
                                    });

                            }, function() {});
                        }
                    });
                }
                break;
            }

            case 'event-to-preStorage'://预入库
            {
                if(datas.length == 0) {
                    return layer.alert('尚未选中数据');
                }
                var choooseDatas = JSON.stringify(datas);
                var w = ($(window).width() * 0.7);
                var h = ($(window).height() - 50);
                layer.open({
                    shadeClose:true,
                    area: [w + 'px', h + 'px'],
                    title: '预入库',
                    content: `
							<form class="layui-form">
							  <div class="layui-form-item">
							  	 <label class="layui-form-label">预计入库时间</label>
								 <div class="layui-input-block">
								 	<input type="text" class="layui-input" lay-verify="required" id="choose_date" placeholder="选择预计入库时间">
								 </div>
							  </div>
							  <div class="layui-form-item">
								<label class="layui-form-label">物流方式</label>
								<div class="layui-input-block">
								  <input type="text" name="logisticsMode" id="logisticsMode" lay-verify="required" placeholder="请输入物流方式" class="layui-input">
								</div>
							  </div>
							  <div class="layui-form-item">
								<label class="layui-form-label">物流编码</label>
								<div class="layui-input-block">
								  <input type="text" name="trackingNumber" id="trackingNumber" lay-verify="required" placeholder="请输入物流编码" class="layui-input">
								</div>
							  </div>
							</form>
						`,
                    success: function(layero, index) {},
                    yes: function (index, layero) {
                        layer.msg('处理中', {
                            icon: 16,shade: 0.01
                        });
                        var estimatedArrivalTime = $('#choose_date').val();
                        var logisticsMode = $('#logisticsMode').val();
                        var trackingNumber = $('#trackingNumber').val();
                        $http.post('/api/inter/tccAssembleError/preStorage', {}, {params: {
                                choooseDatas: choooseDatas,
                                estimatedArrivalTime:estimatedArrivalTime,
                                logisticsMode:logisticsMode,
                                trackingNumber:trackingNumber
                        }})
                            .success(function (res) {
                                if (data.code == 0) {
                                    layer.msg(data.msg);
                                    setTimeout(function(){
                                        layer.closeAll();
                                        location.reload();
                                    }, 3000);
                                } else {
                                    layer.msg(data.msg);
                                    layer.closeAll();
                                }
                            })
                            .error(function(result){
                                layer.close();
                                layer.msg("操作失败，请稍后再试！", {icon: 2});
                            });
                    }
                });
                layui.use(function(){
                    var laydate = layui.laydate;
                    // 日期选择器
                    laydate.render({
                        elem: '#choose_date',
                        //type: 'month'
                    });
                });
                break;
            }

        };
    }
}

//表格双击
app.controller('dbClickCtrl', ['$scope', '$http', DbClickController]);
function DbClickController($scope, $http){
    $scope.doubleClick = function(data) {
        window.top.add_tab('组装报错单 - 详情','/web/storage/tccAssembleError/toDetail?id=' + data.id);
    }
}


